<template>
  <!--  override规则模板 -->
  <div>
    <!-- 按钮与搜索 -->
    <el-row class="overrideRule container">
      <el-col style="margin-right: 10px" class="content-left">
        <!-- 操作区域 -->
        <upper-template
          exportIcon
          importIcon
          :configIcon="false"
          @search="(searchForm.page = 1), searchFunc()"
          @clear="
            (searchForm.accountNum = '')
          "
        >
          <!-- 操作按钮区 -->
          <template slot="buttonArea" >
            <el-button @click="addOrEditFunc('1')">新增</el-button>
            <el-button @click="addOrEditFunc('2')">编辑</el-button>
            <el-button @click="delFunc()">删除</el-button>
            <el-button @click="addOrEditFunc('3')">查看</el-button>
          </template>
          <div slot="exportArea">
                  <!-- 导出操作区域 -->
              <el-button @click="exportExcel('1')"
              >导出模板</el-button>
              <el-button @click="exportExcel('2')"
              >导出数据</el-button> 
         </div>
          <!-- 导入 -->
          <div slot="importArea">
                  <!-- 导入操作区域 -->
                  <el-upload
                    accept=".xls, .xlsx"
                    ref="upload"
                    :multiple="false"
                    :before-upload="beforeUpload"
                    :show-file-list="false"
                    action
                    :limit="1"
                    :http-request="uploadFile"
                  >
                    <el-button>导入</el-button>
                  </el-upload>
          </div>
          <!-- 搜索区 -->
          <template slot="searchArea">
            <el-form
              :model="searchForm"
              ref="searchForm"
              label-width="107px"
              label-position="left"
              size="mini"
            >
              <el-form-item label="账号：">
                <el-input
                  v-model="searchForm.accountNum"
                  style="width: 150px"
                ></el-input>
              </el-form-item>
              
              <el-form-item label="生效日期：">
                <el-date-picker
                  v-model="searchForm.effectDate"
                  value-format="yyyy-MM-dd"
                  type="date"
                  style="width: 150px"
                ></el-date-picker>
              </el-form-item>
              <el-form-item label="截止日期：">
                <el-date-picker
                  v-model="searchForm.invalidDate"
                  value-format="yyyy-MM-dd"
                  type="date"
                  style="width: 150px"
                ></el-date-picker>
              </el-form-item>
            </el-form>
          </template>
        </upper-template>
        <!-- 列表 -->
        <el-table
          ref="multipleTable"
          :data="tableData"
          style="width: 100%"
          @row-click="authorizeFor"
        >
          <el-table-column
            width="55"
            type="selection"
          ></el-table-column>
          <el-table-column label="账号" prop="accountNum" align="left" header-align="center" 
					:filter-multiple="true" :show-overflow-tooltip="true">
				  </el-table-column>
          <el-table-column label="定价曲线" prop="curveId" align="center" header-align="center"
					:filter-multiple="true" :formatter="formatCurveId" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="定价方法" prop="ftpMethodId" align="center" header-align="center"
					:filter-multiple="true" :formatter="formatFtpMethodId" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="指定类型" prop="assignType" align="center" header-align="center"
					:filter-multiple="true" :formatter="formatAssignType" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="指定期限" prop="assignTerm" align="center" header-align="center"
					:filter-multiple="true" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="利差值" prop="intDiff" align="right" header-align="center"
					:filter-multiple="true" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="指定利率值" prop="assignRate" align="right" header-align="center"
					:filter-multiple="true" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="是否计算调整项" prop="adjFlag" align="center" header-align="center"
					:filter-multiple="true" :formatter="row => (row.adjFlag == 1 ? '是' : '否')">
				</el-table-column>
				<el-table-column label="开始追溯日期" prop="retrospectSd" align="center" header-align="center"
					:filter-multiple="true" :formatter="dateformatter" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="截止追溯日期" prop="retrospectEd" align="center" header-align="center"
					:filter-multiple="true" :formatter="dateformatter" :show-overflow-tooltip="true">
				</el-table-column>
				<el-table-column label="跟踪日期类型" prop="trackDateType" align="center" header-align="center"
					:filter-multiple="true" :formatter="formatTrackDateType" :show-overflow-tooltip="true">
				</el-table-column>
 
          <el-table-column
            prop="effectDate"
            :show-overflow-tooltip="true"
            label="生效日期"
            sortable
          >
            <template slot-scope="scope">
              <div v-if="scope.row.effectDate">
                {{ timeFormatShort(scope.row.effectDate) }}
              </div>
              <div v-else>-</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="invalidDate"
            :show-overflow-tooltip="true"
            label="生效截止日"
            sortable
          >
            <template slot-scope="scope">
              <div v-if="scope.row.invalidDate">
                {{ timeFormatShort(scope.row.invalidDate) }}
              </div>
              <div v-else>-</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="creator"
            label="创建人"
            :show-overflow-tooltip="true"
          ></el-table-column>
          <el-table-column
            prop="createdTm"
            :show-overflow-tooltip="true"
            label="创建时间"
            sortable
          >
            <template slot-scope="scope">
              <div v-if="scope.row.createdTm">
                {{ timeFormat(scope.row.createdTm) }}
              </div>
              <div v-else>-</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="modifier"
            :show-overflow-tooltip="true"
            label="修改人"
            sortable
            :formatter="(row) => row.modifier || '-'"
          >
          </el-table-column>
          <el-table-column
            prop="modifiedTm"
            :show-overflow-tooltip="true"
            label="修改时间"
            sortable
          >
            <template slot-scope="scope">
              <div v-if="scope.row.createdTm">
                {{ timeFormat(scope.row.modifiedTm) }}
              </div>
              <div v-else>-</div>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="searchForm.page"
          :page-size="searchForm.size"
          @refresh="searchFunc"
          :total="total"
        ></pagination>
      </el-col>
    </el-row>
    <!-- 新增、编辑弹窗 -->
    <el-dialog
      v-dialogDrag
      :title="titleName"
      :visible.sync="overrideRuleAddAndEditDi"
      width="50%"
      top="2%"
    >
      <el-form
        :model="saveRuleForm"
        ref="saveRuleFormRef"
        label-width="180px"
        label-position="right"
        :rules="saveRuleFormRules"
      >
      
        <el-row>
          <el-col :span="15">
            <el-form-item label="账号：" prop="accountNum" >
              <el-input
                v-model.trim="saveRuleForm.accountNum"
                maxlength="50"
                :disabled="ruleOperateType==2 || ruleOperateType==3"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="是否计算调整项：" prop="adjFlag" >
              <el-select v-model="saveRuleForm.adjFlag" placeholder="请选择" style="width: 100%" :disabled="ruleOperateType == 3">
              <el-option v-for="item in adjFlagList" :key="item.value" :label="item.label" :value="item.value"/>
            </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="15">
            <el-form-item label="追溯开始日期：" prop="retrospectSd" >
              <el-date-picker
                v-model="saveRuleForm.retrospectSd"
                value-format="yyyy-MM-dd"
                type="date"
                style="width: 100%"
                :disabled="ruleOperateType==3" 
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="追溯结束日期：" prop="retrospectEd" >
              <el-date-picker
                v-model="saveRuleForm.retrospectEd"
                value-format="yyyy-MM-dd"
                type="date"
                style="width: 100%"
                :disabled="ruleOperateType==3"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="15">
            <el-form-item label="生效日期：" prop="effectDate" >
              <el-date-picker
                v-model="saveRuleForm.effectDate"
                value-format="yyyy-MM-dd"
                type="date"
                style="width: 100%"
                :disabled="ruleOperateType==3" 
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="15">
            <el-form-item label="生效截止日：" prop="invalidDate" >
              <el-date-picker
                v-model="saveRuleForm.invalidDate"
                value-format="yyyy-MM-dd"
                type="date"
                style="width: 100%"
                :disabled="ruleOperateType==3"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="15">
            <el-form-item label="定价方法：" prop="ftpMethodId" >
              <el-select :disabled="ruleOperateType == 3"
                v-model="saveRuleForm.ftpMethodId"
                placeholder="请选择"
                style="width: 100%"
                @change="ftpMethodChange"
              >
                <el-option
                  v-for="item in ftpMethods"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="assignTypeDi">
          <el-col :span="15">
            <el-form-item label="指定类型：" prop="assignType">
              <el-select
                v-model="saveRuleForm.assignType"
                placeholder="请选择"
                style="width: 100%"
                @change="assignTypeChange"
                :disabled="ruleOperateType == 3"
              >
                <el-option
                  v-for="item in assignTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="assignRateDi">
          <el-col :span="15">
            <el-form-item label="指定利率值(%)：" prop="assignRate" >
              <el-input
                v-model.trim="saveRuleForm.assignRate"
                maxlength="40"
                :disabled="ruleOperateType == 3"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="assignTermDi">
          <el-col :span="15">
            <el-form-item label="指定期限：" prop="assignTermL">
              <el-col :span="14">
                <el-input
                  v-model="saveRuleForm.assignTermL"
                  maxlength="40"
                  :disabled="ruleOperateType == 3"
                ></el-input>
              </el-col>
              <el-col :span="10">
                <el-select 
                  v-model="saveRuleForm.assignTermR"
                  placeholder="请选择"
                  style="width: 100%"
                  :disabled="ruleOperateType == 3"
                >
                  <el-option
                    v-for="item in assignTerms"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-col>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="intDiffDi">
          <el-col :span="15">
            <el-form-item label="利差值：" prop="intDiff" >
              <el-input
                v-model.trim="saveRuleForm.intDiff"
                maxlength="40"
                :disabled="ruleOperateType == 3"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="curveIdDi">
          <el-col :span="15">
            <el-form-item label="定价曲线：" prop="curveId">
              <el-select
                v-model="saveRuleForm.curveId"
                placeholder="请选择"
                style="width: 100%"
                :disabled="ruleOperateType == 3"
              >
                <el-option
                  v-for="item in curveIds"
                  :key="item.curveCode"
                  :label="item.curveName"
                  :value="item.curveCode"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="trackDateTypeDi">
          <el-col :span="15">
            <el-form-item label="跟踪日期类型：" prop="trackDateType">
              <el-select
                v-model="saveRuleForm.trackDateType"
                placeholder="请选择"
                style="width: 100%"
                :disabled="ruleOperateType == 3"
              >
                <el-option
                  v-for="item in trackDateTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" v-if="ruleOperateType != '3'">
         <el-button @click="saveFunc">确 定</el-button>
         <el-button @click="overrideRuleAddAndEditDi = false">取 消</el-button>
      </div>
    </el-dialog> 
    <!-- 新增、编辑弹窗 -->
    
  </div>
</template>

<script>
import { publicManage_pub,overrideRule } from "@/api/index";
import upperTemplate from "@/components/upperTemplate.vue";
import moment from "moment";
import { getDict } from "@/api/getDict";
export default {
  //定义数据
  data() {
    return {
      searchForm: {
        accountNum:"",
        effectDate: "",
        invalidDate: "",
        ruleStatus: "1",
        page: 1,
        size: 15,
      },
      ruleOperateType: "",
      total: 0,
      titleName: "",
      overrideRuleDi: false,
      tableData: [],

      //定价方法数组
      ftpMethods: [
        { value: "1", label: "指定利率法" },
        { value: "4", label: "利率差额法" },
      ],
      adjFlagList:[
        { value: "0", label: "否" },
        { value: "1", label: "是" },
      ],

      //指定期限或利率值
      assignTypes: [],
      //指定期限数组
      assignTerms: [],
      //跟踪日期类型数组
      trackDateTypes: [],
      //定价曲线数组
      curveIds: [],

      //定价曲线
      curveIdDi: false,
      //跟踪日期类型标识
      trackDateTypeDi: false,
      //指定利率值标识
      assignRateDi: false,
      //指定期限标识
      assignTermDi: false,
      //利差值标识
      intDiffDi: false,
      //指定类型标识
      assignTypeDi: false,

      overrideRuleAddAndEditDi: false,
      

      saveRuleForm: {
        accountNum:'',
        assignTerm:'',
        adjFlag:'',
        retrospectSd:'',
        retrospectEd:'',
        effectDate:'',
        invalidDate:'',
        ftpMethodId:'',
        assignType:'',
        intDiff:'',
        assignRate:'',
        trackDateType:'',
         curveId:'',
        curveName:'',
      },
      //表单字段规则校验
      saveRuleFormRules: {
        accountNum:[{ required: true, message: '此项为必输项', trigger: 'blur' },
					          {pattern: /^[a-zA-Z0-9_]{1,50}$/,message: "只可输入(1-50)位的英文字母、数字和下划线！"},
                    { validator: this.validateAccountNum, trigger: 'blur' }
					         ],
        ftpMethodId:[{ required: true, message: '此项为必输项', trigger: 'blur' }],
        intDiff:[
                  { required: true, message: '此项为必输项', trigger: 'blur' },
                 { validator: this.validateIntDiff, trigger: 'blur' }
                ],
        assignRate:[
                  { required: true, message: '此项为必输项', trigger: 'blur' },
                    { validator: this.validateAssignRate, trigger: 'blur' }
                   ],
        adjFlag:[{ required: true, message: '此项为必输项', trigger: 'blur' }],
        retrospectSd:[{ required: true, message: '追溯开始日期不能为空', trigger: 'blur' }],
        retrospectEd:[{ required: true, message: '追溯结束日期不能为空', trigger: 'blur' },
                      { validator: this.invalidDateFun2, trigger: "blur" }],
        effectDate:[{ required: true, message: '生效日期不能为空', trigger: 'blur' }],
        invalidDate:[{ required: true, message: '生效截止日不能为空', trigger: 'blur' },
                      { validator: this.invalidDateFun, trigger: "blur" }],
         
      },
      accountNum:"",
    };
  },
  //组件引入
  components: {
    upperTemplate
  },
  //创建初始化
  created() {
   this.searchFunc();
   this.assignTermsInit();
   this.assignTypesInit();
  },
  mounted() {},
  //监控数值变化
  watch: {

  },
  //运算
  computed: {},
  methods: {

  formatFtpMethodId(row){
      return this.$getLabel(row.ftpMethodId, this.ftpMethods);
  },

  formatCurveId(row){
      return this.$getLabel(row.curveId, this.curveIds);
  },
  formatAssignType(row){
      return this.$getLabel(row.assignType, this.assignTypes);
  },
 
   formatTrackDateType(row){
       if (row.trackDateType == "0") {
        return "跟踪起息日";
      } else if (row.trackDateType == "1") {
        return "跟踪数据日期";
      } else if (row.trackDateType == "2") {
        return "跟踪上次重定价日";
      }
    },
    
    //定价方法变化
    /**
     *根据定价方法显示元素
     * 1	指定利率法
     * 4	利率差额法
     */
    ftpMethodChange(val) {
      this.hiddenEleInit();
      if (val == "1") {
        this.assignTypeDi = true;
        this.assignTypesInit();
      } else if (val == "4") {
        this.intDiffDi = true;
        this.changeMethodIdFun();
      }
    },
    //指定期限数组初始化
    assignTermsInit() {
      getDict("ftp_cp_time_type").then((res) => {
        if (res.code == 200) {
          this.assignTerms = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //跟踪日期类型数组初始化
    trackDateTypesInit() {
      getDict("ftp_cp_track_date_cd").then((res) => {
        if (res.code == 200) {
          this.trackDateTypes = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //指定期限或利率值初始化
    assignTypesInit() {
      getDict("ftp_assign_type").then((res) => {
        if (res.code == 200) {
          this.assignTypes = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    //定价曲线数组初始化
    curveIdsInit() {
      // 查询曲线
      publicManage_pub.baseCurveDefQuery({ page: 1, size: 999 }).then(res => {
        if (res.code == 200) {
          this.curveIds = res.data;
        }
      });
    },

    //指定类型变化
    assignTypeChange(val) {
      if (val == "2") {//指定期限
        
        this.assignRateDi = false;
        this.saveRuleForm.assignRate ="";
        this.assignTermDi = true; //指定期限
        this.trackDateTypeDi = true; //跟踪日期类型
        this.curveIdDi = true; //定价曲线
        this.curveIdsInit();
        this.trackDateTypesInit();

      } else if (val == "1") {//指定利率值
        
        this.assignTermDi = false; //指定期限
        this.saveRuleForm.assignTerm ="";
        this.saveRuleForm.assignTermL ="";
        this.saveRuleForm.assignTermR="";
        this.trackDateTypeDi = false;//跟踪日期类型
        this.saveRuleForm.trackDateType="";
        this.curveIdDi = false; //定价曲线
        this.saveRuleForm.curveId="";

        this.assignRateDi = true;
      }
    },
    //页面初始化隐藏元素
    hiddenEleInit() {
      //指定类型标识
      this.assignTypeDi = false;
      //指定期限标识
      this.assignTermDi = false;
      //指定利率值标识
      this.assignRateDi = false;
      //利差值标识
      this.intDiffDi = false;
      //期限类型
      this.termTypeDi = false;
      //清空动态方法表单
      this.emptyDynamicMethod()
    },

    //清空动态方法表单
    emptyDynamicMethod() {
      this.saveRuleForm.intDiff = ""; //利率差值
      this.saveRuleForm.assignType = ""; //指定类型
      this.saveRuleForm.trackDateType = ""; //跟踪日期类型
      this.saveRuleForm.assignRate = ""; // //指定利率值
       
      this.saveRuleForm.assignTerm = ""; //指定期限
      this.saveRuleForm.assignTermL = ""; //指定期限
      this.saveRuleForm.assignTermR = ""; //指定期限
       
      this.saveRuleForm.termType = ""; //期限类型
      this.saveRuleForm.curveId = ""; ////折现曲线
    },

    //   点击行选中
    authorizeFor(row) {
      if (this.$refs.multipleTable) {
        this.$refs.multipleTable.clearSelection();
      }
      this.$refs.multipleTable.toggleRowSelection(row, true);
    },
    //查询列表
    searchFunc() {
     overrideRule.findAll(this.searchForm).then((res) => {
            if (res.code == 200) {
              this.tableData = res.datas.rows;
              this.total = res.datas.total;
            }
      });
    },
   
    
    //事件转换
    timeFormat(val) {
      if (val) return moment(val).format("YYYY-MM-DD HH:mm:ss");
      else return "";
    },
    timeFormatShort(val) {
      if (val) return moment(val).format("YYYY-MM-DD");
      else return "";
    },
    //页码值改变
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.searchForm.size = val;
      this.searchFunc();
    },
    //当前页改变
    handleCurrentChange(val) {
      this.searchForm.page = val;
      console.log(`当前页: ${val}`);
      this.searchFunc();
    },
    
    emptydataTableForm() {
      this.saveRuleForm.retrospectEd = "";
      this.saveRuleForm.retrospectSd = "";
      this.saveRuleForm.effectDate = "";
      this.saveRuleForm.invalidDate = "";
      this.saveRuleForm.accountNum = "";
      this.saveRuleForm.adjFlag = "0";
      this.saveRuleForm.ftpMethodId = "4";
      //回写定价方法选择字段
      this.ftpMethodChange("4");
    },
    //新增、编辑弹窗
    addOrEditFunc(val) {
      this.ruleOperateType = val;
      
      if (this.ruleOperateType === "1") {
        this.hiddenEleInit();
        this.titleName = "新增单账户定价规则信息";
        this.overrideRuleAddAndEditDi = true;
          this.$nextTick(() => {
        //清除校验结果
        this.$refs.saveRuleFormRef.clearValidate();
         });
        //清空表单
        this.emptydataTableForm();
        // this.emptyDynamicMethod();

      } else if (this.ruleOperateType === "2" || this.ruleOperateType === "3") {
        let selection = this.$refs.multipleTable.selection;
        if (selection.length < 1) {
          return this.$message.warning("请选择一条数据");
        } else if (selection.length > 1) {
          return this.$message.warning("只能选择一条数据");
          
        } else {
          
          this.titleName =  "编辑单账户定价规则信息";
          this.overrideRuleAddAndEditDi = true;
          
          //回写定价方法选择字段
          this.ftpMethodChange(selection[0].ftpMethodId);
          //回写指定类型
          this.assignTypeChange(selection[0].assignType);
          this.saveRuleForm = Object.assign({},this.saveRuleForm,selection[0]); 
          this.dataSplit(this.saveRuleForm);
        }
      }
    },
     
     
    //保存
    saveFunc() {
      this.$refs["saveRuleFormRef"].validate((valid) => {
        if (valid) {
          //部分字段拆分成两部分的数据合并
          this.dataMerge();
          let data = {
            operateType: this.ruleOperateType,
            overrideAccount: { ...this.saveRuleForm },
          };
          overrideRule.save(data).then((res) => {
            if (res.code === 200) {
              this.overrideRuleAddAndEditDi = false;
              this.$message.success("保存成功");
              this.searchFunc();
            } else {
              this.$message.error(res.message || "保存失败");
            }
          });
        } else {
          this.$message.warning("请填写正确的信息！");
        }
      });
    },
    // 删除
    delFunc() {
      let selection = this.$refs.multipleTable.selection;
      if (selection.length < 1) {
        return this.$message.warning("请选择要删除的数据");
      }
      this.$confirm("您确定要删除选中数据吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let data = { ids: selection.map((v) => v.accountNum) };
          overrideRule.remove(data).then((res) => {
            if (res.code == 200) {
              this.$message.success("删除成功");
              this.searchFunc();
            } else {
              this.$message.error(res.message || "删除失败");
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

     //部分字段拆分成两部分的数据合并
    dataMerge() {
      if (
        this.saveRuleForm.assignTermL != "" &&
        this.saveRuleForm.assignTermR != ""
      ) {
        this.saveRuleForm.assignTerm =
          this.saveRuleForm.assignTermL + this.saveRuleForm.assignTermR;
      }
    },
    //部分字段拆分成两部分
    dataSplit() {
      if (this.saveRuleForm.assignTerm != "" && this.saveRuleForm.assignTerm != undefined && this.saveRuleForm.assignTerm === this.saveRuleForm.assignTerm ) {
        this.saveRuleForm.assignTermL = this.saveRuleForm.assignTerm.substr(
          0,
          this.saveRuleForm.assignTerm.length - 1
        );
        this.saveRuleForm.assignTermR = this.saveRuleForm.assignTerm.substr(
          this.saveRuleForm.assignTerm.length - 1,
          1
        );
      }
      
    },


 
    changeMethodIdFun(){
			let ftpMethodId = this.saveRuleForm.ftpMethodId;
			let assignType =this.saveRuleForm.assignType;
			// 定价方法链接操作，（不同定价方法显示不同1：指定利率法,2：利率差额法）
			if(ftpMethodId=="1"){
				//指定类型
				this.assignTypeDi=true;
				//利差值
				this.intDiffDi=false;
				this.saveRuleForm.intDiff='';
				// 定价方法链接操作，（1：指定利率值; 2:指定期限）
				if(assignType=="1"){
					//指定利率值
					this.assignRateDi=true;
					//跟踪日期类型
					this.trackDateTypeDi=false;
					this.saveRuleForm.trackDateType='';
					//指定期限
					this.assignTermDi=false;
					this.saveRuleForm.assignTerm='';
					//定价曲线
					this.curveIdDi=false;
					this.saveRuleForm.curveId='';

				}else if(assignType=="2"){
					//指定期限
					this.assignTermDi=true;
					//跟踪日期类型
					this.trackDateTypeDi=true;
					//定价曲线
					this.curveIdDi=true;
					// this.$nextTick(_ => {
				  //       this.$refs.paramTableCurve.refresh();
					// });
					//指定利率值
					this.assignRateDi=false;
					this.saveRuleForm.assignRate='';
				}

			}else if(ftpMethodId=="4"){
				//指定类型
				this.assignTypeDi=false;
				this.saveRuleForm.assignType='';
				//指定利率值
				this.assignRateDi=false;
				this.saveRuleForm.assignRate='';
				//指定期限
				this.assignTermDi=false;
				this.saveRuleForm.assignTerm='';
				//跟踪日期类型
				this.trackDateTypeDi=false;
				this.saveRuleForm.trackDateType='';
				//定价曲线
				this.curveIdDi=false;
				this.saveRuleForm.curveId='';
				//利差值
				this.intDiffDi=true;
			}
	},
  dateformatter(rows,column){
		let date___ = new Date(rows[column.property]);
		return date___.getFullYear()+'-'+(date___.getMonth()+1)+'-'+date___.getDate();
	},

  validateAccountNum(rule, value, callback){
		if(this.ruleOperateType == "1"){
			if (value === '') {
				callback(new Error('此项为必输项'));
		  } else {
            let data ={accountNum:this.saveRuleForm.accountNum};
            overrideRule.checkUsing(data).then((res) => {
              if (res.code == 200) {
                if (res.data == 'false') 
                  callback();
                  else
                      callback(new Error('该账户已存在！'));
              }
            });
	    }
		} else {
      callback();
    }
	},
  //利差值输入框校验
    validateIntDiff(rule, value, callback){//doubleData
     
    	let regExp1 = new RegExp("^[-]?[1-9]?[\\d]([.][\\d]{1,6})?$");//整数位小于等于两位，小数位小于等于6位的正数、负数和0
    	if(!regExp1.test(this.saveRuleForm.intDiff)){
        return callback(new Error("只能输入整数位小于等于两位，小数位小于等于6位的正数、负数和零！"));
      }else callback();
    },
	//指定利率值输入框校验
	validateAssignRate(rule, value, callback){//doubleData
      
    	let intLength = 8 - 6; //整数部分长度
    	let decimalLength = 6; //小数部分长度
		if(decimalLength == 0){
			let regExp = new RegExp("^[0-9]{0,2}$");
	 		if(!regExp.test(this.saveRuleForm.assignRate)){
	 			return callback(new Error("只能输入"+intLength+"位正整数！"));
	    }else callback();
		}else{
			let regExp1 = new RegExp("^[\\d]{0,"+intLength+"}\\.[\\d]{0,"+decimalLength+"}$");
			let regExp2 = new RegExp("^[\\d]{0,"+intLength+"}$");
			if((!regExp1.test(this.saveRuleForm.assignRate)) && (!regExp2.test(this.saveRuleForm.assignRate))){
				callback(new Error("只能输入整数位小于"+intLength+"位，小数位小于"+decimalLength+"位的数字！"));
			}else callback();
		}
	},
   invalidDateFun(rule, value, callback){
      
    	var effectDate = this.saveRuleForm.effectDate;
      var invalidDate = this.saveRuleForm.invalidDate;
      var date1 = new Date(Date.parse(effectDate.replace("-","/")));
      var date2 = new Date(Date.parse(invalidDate.replace("-","/")));
		
        if (date1 > date2) {
        	return callback(new Error("生效截止日必须大于等于生效日期!"));
        }else{
          return callback();
        }
    },
    invalidDateFun2(rule, value, callback){
       
    	var retrospectSd = this.saveRuleForm.retrospectSd;
      var retrospectEd = this.saveRuleForm.retrospectEd;
      var date1 = new Date(Date.parse(retrospectSd.replace("-","/")));
      var date2 = new Date(Date.parse(retrospectEd.replace("-","/")));
		
        if (date1 > date2) {
        	return callback(new Error("追溯结束日期必须大于等于追溯开始日期!"));
        }else{
           callback();
        }
    },
    //导出文件
    exportExcel(tmpFlag) {

      let selection = this.$refs.multipleTable.selection;
      let param = {
        hasTemplete: tmpFlag, //1为导出模板
        accountNum: this.searchForm.accountNum,  
        effectDate: this.searchForm.effectDate,
        invalidDate: this.searchForm.invalidDate,
        selectedData: selection.map((v) => v.accountNum)
      };

      overrideRule
        .exp(param)
        .then((res) => {
          if (res) {
            var filename = decodeURI(res.headers["content-disposition"]).split("=")[1];
            let contenttype =
              filename.substring(filename.lastIndexOf("."), filename.length) === "xlsx"
                ? "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
                : "application/vnd.ms-excel;charset=utf-8";
            const content = res.data;
            const blob = new Blob([content], {
              type: contenttype,
            });
            let url = window.URL.createObjectURL(blob);
            let link = document.createElement("a");
            link.style.display = "none";
            link.href = url;
            link.setAttribute("download", filename);
            document.body.appendChild(link);
            link.click();
          }
        })
        .catch(function (error) {
          console.log(error);
          // this.$message.error("导出失败！");
        });
    },
     // 上传文件之前的钩子
    beforeUpload(file) {
      let name = file.name;
      let type = name.substring(name.lastIndexOf("."), name.length);
      if (type === ".xls" || type === ".xlsx") {
        return true;
      } else {
        this.$message.warning("只能选择xls或者xlsx格式的文件上传");
        return false;
      }
    },
     // 上传文件
    uploadFile(item) {
      let form = new FormData();
      // 文件对象
      form.append("excelFile", item.file);
      // 发送请求
      overrideRule.imp(form)
        .then((res) => {
          if (res.code == 200) {
            this.$message.success("导入成功");
            this.searchFunc();
          } else {
            this.$message.error(res.message);
          }
          this.$refs.upload.clearFiles();
        })
        .catch((err) => {
          this.$refs.upload.clearFiles();
        });
    },
 








  }
  

};
</script>


<style lang="scss" scoped>
.buessinessEleTable .el-table__header th {
  /deep/ .cell {
    white-space: nowrap !important;
  }
}

/deep/.el-dialog__body {
  max-height: 400px;
}
.tipMessage {
  line-height: 32px;
  margin-left: 5px;
  color: red;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500 !important;
  font-size: 12px !important;
}
.selectBox {
  background: url("~@/assets/images/select_btn.gif");
  background-repeat: no-repeat;
  height: 26px;
  width: 23px;
  position: absolute;
  right: 0;
  top: 5px;
  cursor: pointer;
}
.el-popover {
  max-height: 160px;
  overflow: auto;
}

.right {
  float:right;
  width:50%
}

.left {
  float:left;
  width:50%
}
</style>